package com.wpre.springhomework;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-10-25
 * Time: 14:32
 */
@RequestMapping("/massage")
@RestController
public class MassageController {

    List<MassageInfo> massageInfos = new ArrayList<>();

    @RequestMapping("/getList")
    public List<MassageInfo> getList() {
        return massageInfos;
    }

    //设置返回值为json
    @RequestMapping(value = "/publish",produces = "application/json")
    //接收json参数
    public String publish(@RequestBody MassageInfo massageInfo) {
        if (StringUtils.hasLength(massageInfo.getFrom())
                && StringUtils.hasLength(massageInfo.getTo())
                && StringUtils.hasLength(massageInfo.getMassage())) {

            massageInfos.add(massageInfo);
            return "{\"ok\":1}";
        }

        return "{\"ok\":0}";
    }
}
